﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;

namespace Zealib.Extensions
{
    /// <summary>
    /// Extensions for <seealso cref="System.Object"/> class.
    /// </summary>
    public static class ObjectExtensions
    {
        /// <summary>
        /// If whether the specified <paramref name="self"/> are the null, throw <see cref="System.NullReferenceException"/>.
        /// </summary>
        /// <param name="self">Instance</param>
        public static void IsNotNull(this object self)
        {
            if (ReferenceEquals(self, null)) throw new NullReferenceException();
        }


        /// <summary>
        /// Returns an indication whether the specified <paramref name="self"/> is an anonymous object.
        /// </summary>
        /// <param name="self">anonymous object.</param>
        /// <returns>true if <paramref name="self"/> is an anonymous object; otherwise, false.</returns>
        public static bool IsAnonymousObject(this object self)
        {
            self.IsNotNull();
            return self.GetType().IsAnonymous();
        }


        /// <summary>
        /// Returns an indication whether the specified <paramref name="self"/> is an closure object.
        /// </summary>
        /// <param name="self">closure object.</param>
        /// <returns>true if <paramref name="self"/> is an closure object; otherwise, false.</returns>
        public static bool IsClosureObject(this object self)
        {
            self.IsNotNull();
            return self.GetType().IsClosure();
        }

    }
}
